I am new in iOS programming so I am getting some serious problem in our code. I have getting problem in our asset library code, this code is written in the viewDidLoad: method but when I run the application viewDidLoad: method executes but my asset library code is not executing, it will execute after the execution of other method of application. So, the asset urls that I am fetching from the device library I am unable to display those data into our table view.
this is my assetLibrary code it is not executing with the viewDidLoad: method:
ALAssetLibrary *assetLibrary = [[ALAssetLibrary alloc] init];
[_assetLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop){
[group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop){
if([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto]){
[urls addObject:[result valueForProperty:ALAssetPropertyURLs]];
}
});
} failureBlock:^(NSError *error){
NSLog(@"Failure");
}];
I google it but I don't find any perfect solution.
Please help me.
Tarun Kumar
18-Jan-2016The problem you are specifying is not unique so don't worry, every iOS developer face that problem.
To execute ALAssetLibrary code with the viewDidLoad: method you need to implement dispatch_queue_t in your code and dispatch your queue in syncronized manner using dispatch_sync.
Write your ALAssetLibrary code in this dispatch_queue_t code.
See the code below: